﻿<WindowView 
    x:Name="This"
    x:Class="Poet.Views.TrunkView"  
    Icon="/Poet;component/App.ico"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:views="clr-namespace:Poet.Views"   
    Top="{ViewModel DefaultValue=NaN}" 
    Left="{ViewModel DefaultValue=NaN}"  
    Width="{ViewModel DefaultValue=966}" 
    Height="{ViewModel DefaultValue=600}"  
    Topmost="{ViewModel DefaultValue=false}" 
    ResizeMode="{ViewModel DefaultValue=CanResizeWithGrip}"  
    WindowStyle="{ViewModel DefaultValue=SingleBorderWindow}" 
    WindowState="{Binding WindowState}" 
    ShowInTaskbar="{Binding ShowInTaskbar}" 
    WindowStartupLocation="CenterScreen"
    ShowActivated="True"
    Title="Poet">

    <WindowView.InputBindings>
        <KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="Save" CommandParameter="All"/>
        <KeyBinding Key="F4" Command="ApplicationCommands.Properties" CommandParameter="About"/>
        <KeyBinding Key="F5" Command="ApplicationCommands.Properties" CommandParameter="SetAssotiations"/>
        <KeyBinding Key="F4" Modifiers="Alt" Command="ApplicationCommands.Close" CommandParameter="App"/>
        <KeyBinding Key="X" Modifiers="Alt+Shift" Command="ApplicationCommands.Close" CommandParameter="All"/>
    </WindowView.InputBindings>

    <WindowView.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Resources\XamlStore.xaml"/>
                <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <SwitchConverter x:Key="StatusBarItemsSelector" TypeMode="True">
                <SwitchConverter.Default>
                    <XamlCollection>
                        <StatusBarItem Margin="2 0 0 0" Content="{Binding ActiveDocumentView.Title, FallbackValue={Localizing None}}"/>
                    </XamlCollection>
                </SwitchConverter.Default>
                <Case Key="{x:Type views:DocumentView}" Value="{StaticResource StatusBarItems}"/>
            </SwitchConverter>
            <SwitchConverter x:Key="StatusBarToolTipSelector" TypeMode="True">
                <SwitchConverter.Default>
                    <ToolTip Content="{Localizing EmptyMessage}"/>
                </SwitchConverter.Default>
                <Case Key="{x:Type views:DocumentView}" Value="{StaticResource StatusBarToolTip}"/>
            </SwitchConverter>
        </ResourceDictionary>
    </WindowView.Resources>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Menu 
            Name="Menu"
            IsMainMenu="True"
            ItemsSource="{StaticResource MainMenuItems}"
            Background="{Binding ElementName=ToolBarTray, Path=Background}"
            MouseDoubleClick="ChangeWindowState"
            PreviewMouseMove="DragMove">
            <Menu.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="..\Resources\MenuResources.xaml"/>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </Menu.Resources>
        </Menu>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <StackPanel.Resources>
                <BooleanConverter x:Key="PinConverter" OnFalse="{Picture Pin, 13}" OnTrue="{Picture Unpin, 13}"/>
            </StackPanel.Resources>
            <ToggleButton Focusable="False" IsChecked="{ViewModel Topmost}" ToolTip="{Localizing Topmost}" Content="{ViewModel Topmost, Converter={StaticResource PinConverter}}" HorizontalAlignment="Right" Margin="1"/>
            <Button Focusable="False" Command="ApplicationCommands.Close" CommandParameter="App" ToolTip="{Localizing Exit}" Content="{Picture PinClose.png, 13}" HorizontalAlignment="Right" Margin="1"/>
        </StackPanel>

        <ToolBarTray 
            Grid.Row="1" 
            Name="ToolBarTray" 
            MouseDown="DragMove" 
            MinHeight="27"
            Visibility="{ViewModel ShowToolBarTray, DefaultValue=True}">
            <ToolBarTray.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="..\Resources\ToolBarTrayResources.xaml"/>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </ToolBarTray.Resources>
            <ToolBarTray.ContextMenu>
                <ContextMenu ItemsSource="{VisibilityMenuItems SourceName=ToolBarTray, SourcePropertyName=ToolBars, StyleStaticKey=CheckableItemStyle}"/>
            </ToolBarTray.ContextMenu>
        </ToolBarTray>

        <DockingManager
            Grid.Row="2"
            Name="DockingManager"
            AllowDrop="True" 
            Drop="DockingManagerDrop"
            DocumentsSource="{Binding DocumentViews}" 
            ActiveContent="{Binding ActiveContent, Mode=TwoWay}"
            ActiveDocument="{Binding ActiveDocumentView, Mode=TwoWay}"
            MouseDoubleClick="DockingManagerMouseDoubleClick">
            <ResizingPanel Orientation="Horizontal">
                <DocumentPane/>
                <DockablePane Name="Pane" ResizingPanel.ResizeWidth="200" ItemsSource="{StaticResource Tools}"/>
            </ResizingPanel>
        </DockingManager>

        <StatusBar
            Grid.Row="3" 
            MinHeight="22"
            ItemsSource="{Binding ActiveDocumentView, Converter={StaticResource StatusBarItemsSelector}}"
            PreviewMouseDoubleClick="ChangeWindowState"
            Visibility="{ViewModel ShowStatusBar, DefaultValue=True}"
            Background="{Binding ElementName=Menu, Path=Background}"
            ToolTip="{Binding ActiveDocumentView, Converter={StaticResource StatusBarToolTipSelector}}"
            ToolTipService.ShowDuration="32000000"
            ToolTipService.IsEnabled="{ViewModel ShowStatusBarToolTip, DefaultValue=True}">
            <StatusBar.Resources>
                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource StatusBarTextBlockStyle}">
                    <Setter Property="DataContext" Value="{Binding ActiveDocumentView.DataContext}"/>
                </Style>
                <Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource {x:Type ToolTip}}">
                    <Setter Property="DataContext" Value="{Binding ActiveDocumentView.DataContext}"/>
                </Style>
            </StatusBar.Resources>
        </StatusBar>

    </Grid>
</WindowView>